home *** CD-ROM | disk | FTP | other *** search
- /* File strlist.h Copyright (C) 1995, 1996 by John R. Montbriand. All Rights Reserved. */
-
- #ifndef __STRLIST__
- #define __STRLIST__
-
- /* File strlist.h
-
- Copyright (C) 1995, 1996 by John Montbriand. All Rights Reserved.
-
- Distribute freely in areas where the laws of copyright apply.
-
- Use at your own risk.
-
- Do not distribute modified copies.
-
- These various string list libraries are for free!
-
- See the file strlist.txt for details.
-
- */
-
- #include <Types.h>
- #include <Menus.h>
- #include <Lists.h>
-
-
- /* version of this library */
-
- #define kStrListVersion 2
-
-
- /* SLUSECASE determines if the routines that compare strings are
- case sensitive or not. if SLUSECASE is true, all comparisons
- are case sensitive, otherwise, if SLUSECASE is false, all comparisons
- are non case sensitive. */
-
- #ifndef SLUSECASE
- #define SLUSECASE false
- #endif
-
- #ifdef __cplusplus
- extern "C" {
- #endif
-
-
- /* routines for creating and retrieving string lists */
-
- /* NewStringList makes a new string list containing no strings */
- Handle NewStringList(void);
-
- /* MakeStringList makes a new string list containing n strings
- proviced as c style strings in the ... parameter list. */
- Handle MakeStringList(long n, ...);
-
- /* GetStringList retrieves the STR# resource with the given ID. */
- Handle GetStringList(short id);
-
- /* Get1StringList retrieves the STR# resource with the given ID
- searching only the first resource file in the resource chain. */
- Handle Get1StringList(short id);
-
- /* DisposeStringList recovers the memory occupied by a string list.
- if the handle refers to a resource, ReleaseResource is called,
- otherwise DisposeStringList calls DisposeHandle. */
- void DisposeStringList(Handle list);
-
-
-
- /* routines for retrieving information from string lists */
-
- /* StringListSize returns the number of strings in the STR#. */
- short StringListSize(Handle list);
-
- /* StringListElt returns a pointer to a string in a string list.
- StringListElt returns a pointer to the string data contained
- in the string list handle so be sure to lock the handle
- before calling this function. */
- StringPtr StringListElt(Handle list, short elt);
-
- /* RetrieveIndString copies the indicated string list element from
- the string list into the string pointed to by the_string.
- RetrieveIndString returns the value passed in the third
- parameter, or NULL if the index was out of bounds. */
- StringPtr RetrieveIndString(Handle list, short elt, StringPtr the_string);
-
-
-
- /* routines for using string list maps */
-
- /* MakeStringListMap locks the string list handle in memory
- and returns a handle to an array of string pointers that
- refer to consecutive elements in the string list.
- if the there is not enough memory to create the array,
- the the list is not locked and NULL is returned. */
- StringPtr** MakeStringListMap(Handle list);
-
- /* MakeSortedStringListMap is identical to MakeStringListMap
- except the map returned is sorted in ascending, alphabetical
- order. if SLUSECASE is true, case sensitive ordering is used. */
- StringPtr** MakeSortedStringListMap(Handle list);
-
- /* MapStringListElt returns a pointer to a string in a string list
- using a string list map returned by MakeStringListMap. */
- StringPtr MapStringListElt(StringPtr** string_map, short elt);
-
- /* WithStringList macro. you must declare a variable of type
- StringPtr** and provide it as the map parameter before
- defining this macro. */
- #define WithStringList(stringlist, map) \
- for(map=MakeStringListMap(stringlist);map!=NULL; \
- DisposeHandle((Handle)(map)), HUnlock(stringlist), map=NULL)
-
- /* WithSortedStringList is identical to the WithStringList macro
- except it calls MakeSortedStringListMap */
- #define WithSortedStringList(stringlist, map) \
- for(map=MakeSortedStringListMap(stringlist);map!=NULL; \
- DisposeHandle((Handle)(map)), HUnlock(stringlist), map=NULL)
-
-
-
-
- /* for removing elements from string lists */
-
- /* StringListRemove removes the indicated string from the string list */
- void StringListRemove(Handle list, short elt);
-
- /* ClearStringList empties the string list */
- void ClearStringList(Handle list);
-
-
-
- /* routines for adding strings to string lists */
-
- /* StringListInstall installs the string in the list at the indicated
- element position. */
- void StringListInstall(Handle list, short elt, StringPtr s);
-
- /* StringListAppend adds the string s to the end of the string list. */
- void StringListAppend(Handle list, StringPtr s);
-
- /* StringListPrepend adds the string s to the front of the string list. */
- void StringListPrepend(Handle list, StringPtr s);
-
-
-
- /* routines for inserting strings into alphabetically sorted string lists */
-
- /* StringListInsert inserts the string into the string list
- such that the string list remains alphabetically sorted.
- if SLUSECASE is true, case sensitive ordering is used.
- returns the index of the inserted string. */
- short StringListInsert(Handle list, StringPtr s);
-
- /* StringListRInsert inserts a string into a string list sorted
- in descending order. if SLUSECASE is true, case sensitive
- ordering is used. the index of the inserted string is returned. */
- short StringListRInsert(Handle list, StringPtr s);
-
-
-
- /* for searching for strings in string lists */
-
- /* FindStringList finds the index of the string in the list.
- comparisons are case sensitive if SLUSECASE is true. if
- it's not there, the function returns zero. */
- short FindStringList(Handle list, StringPtr s);
-
-
-
- /* utility functions for working with string lists. */
-
- /* uncomment the following to allow the menu manager to interpret
- special characters when string list elements are added to menus.
- by default, StringListToMenu does not allow this to happen. */
- /* #define INTERPRETMENUCHARS 1 */
-
- /* StringListToMenu converts the string list into a menuhandle
- suitable for putting in the menubar on using as a popup. */
- MenuHandle StringListToMenu(Handle list, short id, StringPtr name);
-
-
- /* StringListToList converts the string list into a menuhandle
- suitable for putting in the menubar on using as a popup. */
- void StringListToList(Handle list, ListHandle the_list);
-
-
-
-
- /* routines for using string lists as sets of strings. each string
- list is treated as a set of strings. all string comparisons
- are control by the SLUSECASE variable. */
-
- /* StringListUnion returns a new string list containing all of the strings
- appearing in both string lists, or NULL if an error occurs. */
- Handle StringListUnion(Handle A, Handle B);
-
- /* StringListIntersection returns a new string list containing
- the strings that appear in both string lists, or NULL
- if an error occurs. */
- Handle StringListIntersection(Handle A, Handle B);
-
- /* StringListDifference returns a new string list containing
- all of the strings appearing in the union of A and B that
- do not appear in the intersection of A and B. */
- Handle StringListDifference(Handle A, Handle B);
-
- /* StringListSubset returns true if the strings contained in
- the string list subs are a subset of the strings contained
- in the string list 'list' */
- Boolean StringListSubset(Handle A, Handle B);
-
- /* StringListEquivalent returns true if string list A
- contains the same set of strings as string list B. */
- Boolean StringListEquivalent(Handle A, Handle B);
-
- #ifdef __cplusplus
- };
- #endif
-
- #endif
-
- /* end of file strlist.h */
-